function ListNode(val, next) {
  this.val = (val === undefined ? 0 : val)
  this.next = (next === undefined ? null : next)
}

function List(arr) {
  const dummyHead = new ListNode()
  let p = dummyHead
  if (Array.isArray(arr)) {
    arr.forEach(el => {
      p.next = new ListNode(el)
      p = p.next
    });
  }
  return dummyHead.next
}

function List2Array(head) {
  let res = []
  let p = head
  while (p) {
    res.push(p.val)
    p = p.next
  }
  return res
}

function TreeNode(val, left, right) {
  this.val = (val === undefined ? 0 : val)
  this.left = (left === undefined ? null : left)
  this.right = (right === undefined ? null : right)
}





module.exports = {
  List,
  List2Array,
  ListNode,
  TreeNode
}